package com.bitmain.mmst.miner.monitor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.bitmain.mmst.domain.MinerState;

/**
 * 
 * @author Richard - rui.wu@bitmain.com
 * @since 2016年7月12日
 *
 */
public enum MinerStateCache {
	INSTANCE;

	private Map<String, MinerState> minerStates;
	
	private MinerStateCache(){
		this.minerStates = new ConcurrentHashMap<>();
	}

	public void put(MinerState minerState) {
		if(minerStates==null){
			minerStates = new HashMap<String, MinerState>();
			minerStates.put(minerState.getHost(), minerState);
		}else{
			minerStates.put(minerState.getHost(), minerState);
		}
	}
	
	public Map<String, MinerState> getPoisedMinerCache() {
		Map<String, MinerState> cache = new ConcurrentHashMap<>();
		cache.putAll(minerStates);
		return cache;
	}
	
	public MinerState pull(String host) {
		return minerStates.get(host);
	}
}
